home *** CD-ROM | disk | FTP | other *** search
- package symantec.itools.db.net;
-
- import java.io.DataInputStream;
- import java.io.DataOutputStream;
- import java.io.EOFException;
- import java.io.IOException;
- import symjava.sql.SQLException;
-
- public class NetData extends ServerObject {
- int _length;
- byte[] _data;
-
- public NetData(byte[] data) {
- this._data = data;
- this._length = data.length;
- }
-
- public NetData(byte[] data, int len) {
- this._data = data;
- this._length = len;
- }
-
- public NetData(byte data) {
- this._length = 1;
- this._data = new byte[this._length];
- this._data[0] = data;
- }
-
- public NetData(short data) {
- this._length = 2;
- this._data = new byte[this._length];
- this._data[0] = (byte)(data >>> 8 & 255);
- this._data[1] = (byte)(data & 255);
- }
-
- public NetData(boolean data) {
- this._length = 1;
- this._data = new byte[this._length];
- this._data[0] = (byte)(data ? 1 : 0);
- }
-
- public NetData(int data) {
- this._length = 4;
- this._data = new byte[this._length];
- this._data[0] = (byte)(data >>> 24 & 255);
- this._data[1] = (byte)(data >>> 16 & 255);
- this._data[2] = (byte)(data >>> 8 & 255);
- this._data[3] = (byte)(data & 255);
- }
-
- public NetData(long data) {
- this._length = 8;
- this._data = new byte[this._length];
- this._data[0] = (byte)((int)(data >>> 56) & 255);
- this._data[1] = (byte)((int)(data >>> 48) & 255);
- this._data[2] = (byte)((int)(data >>> 40) & 255);
- this._data[3] = (byte)((int)(data >>> 32) & 255);
- this._data[4] = (byte)((int)(data >>> 24) & 255);
- this._data[5] = (byte)((int)(data >>> 16) & 255);
- this._data[6] = (byte)((int)(data >>> 8) & 255);
- this._data[7] = (byte)((int)data & 255);
- }
-
- public NetData(float data) {
- this._length = 4;
- this._data = new byte[this._length];
- int i = Float.floatToIntBits(data);
- this._data[0] = (byte)(i >>> 24 & 255);
- this._data[1] = (byte)(i >>> 16 & 255);
- this._data[2] = (byte)(i >>> 8 & 255);
- this._data[3] = (byte)(i & 255);
- }
-
- public NetData(double data) {
- this._length = 8;
- this._data = new byte[this._length];
- long l = Double.doubleToLongBits(data);
- this._data[0] = (byte)((int)(l >>> 56) & 255);
- this._data[1] = (byte)((int)(l >>> 48) & 255);
- this._data[2] = (byte)((int)(l >>> 40) & 255);
- this._data[3] = (byte)((int)(l >>> 32) & 255);
- this._data[4] = (byte)((int)(l >>> 24) & 255);
- this._data[5] = (byte)((int)(l >>> 16) & 255);
- this._data[6] = (byte)((int)(l >>> 8) & 255);
- this._data[7] = (byte)((int)l & 255);
- }
-
- public NetData(String data) {
- this._length = data.length();
- this._data = new byte[this._length];
-
- for(int i = 0; i < this._length; ++i) {
- this._data[i] = (byte)data.charAt(i);
- }
-
- }
-
- public NetData() {
- this._length = 0;
- this._data = new byte[this._length];
- }
-
- int getType() {
- return 51;
- }
-
- void read(DataInputStream in) throws SQLException, IOException, ErrorException {
- this._length = in.readShort();
- if (this._length > 0) {
- this._data = new byte[this._length];
- in.readFully(this._data, 0, this._length);
- }
-
- }
-
- void write(DataOutputStream out) throws IOException {
- out.writeByte(this.getType());
- out.writeShort(this._length);
- if (this._length > 0) {
- out.write(this._data, 0, this._length);
- }
-
- }
-
- public int getInt() throws EOFException {
- if (this._length >= 4) {
- int b1 = this._data[0] & 255;
- int b2 = this._data[1] & 255;
- int b3 = this._data[2] & 255;
- int b4 = this._data[3] & 255;
- return (b1 << 24) + (b2 << 16) + (b3 << 8) + b4;
- } else {
- throw new EOFException();
- }
- }
-
- public short getShort() throws EOFException {
- if (this._length >= 2) {
- int i1 = this._data[0] & 255;
- int i2 = this._data[1] & 255;
- return (short)((i1 << 8) + i2);
- } else {
- throw new EOFException();
- }
- }
-
- public boolean getBool() throws EOFException {
- if (this._length >= 1) {
- int i = this._data[0];
- return i != 0;
- } else {
- throw new EOFException();
- }
- }
-
- public byte getByte() throws EOFException {
- if (this._length >= 1) {
- return (byte)(this._data[0] & 255);
- } else {
- throw new EOFException();
- }
- }
-
- public long getLong() throws EOFException {
- if (this._length >= 8) {
- int i1 = this.getInt();
- int b1 = this._data[4] & 255;
- int b2 = this._data[5] & 255;
- int b3 = this._data[6] & 255;
- int b4 = this._data[7] & 255;
- int i2 = (b1 << 24) + (b2 << 16) + (b3 << 8) + b4;
- return ((long)i1 << 32) + ((long)i2 & 4294967295L);
- } else {
- throw new EOFException();
- }
- }
-
- public float getFloat() throws EOFException {
- return Float.intBitsToFloat(this.getInt());
- }
-
- public double getDouble() throws EOFException {
- return Double.longBitsToDouble(this.getLong());
- }
-
- public byte[] getBytes() {
- return this._data;
- }
- }
-